pluginHome = new File("./plugins").listFiles().find { it.name.startsWith('cloud-tools-')}
if(pluginHome == null) pluginHome = "."

includeTargets << new File( "${pluginHome}/scripts/CloudToolsInit.groovy" )

target('default': "Runs SQL From S3") {
	sql()
}

target(sql: "The implementation task") {
    depends( initCloudToolsService)
    cloudToolsService.withCluster { clusterManager, clusterName, cluster ->
		if(System.getProperty("cloudtools.sql.script") != null){
			List<String> scripts = new ArrayList<String>();
		    scripts.add(System.getProperty("cloudtools.sql.script"));
		    cluster.executeSqlScripts(scripts);
			event('StatusFinal', ['Finished with sql'])
		}else{
			event('StatusError', ['You specify cloudtools.sql.script.  Example:\ngrails -Dcloudtools.sql.script=./foo.sql cloud-tools-sql'])
		}
	}
}
